package com.isunland.managesystem.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.BaseParams;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.FunctionObject;
import com.isunland.managesystem.entity.GenerateCodeParams;
import com.isunland.managesystem.entity.SimpleWebViewParams;
import com.isunland.managesystem.ui.AgriculturalForumListFragment;
import com.isunland.managesystem.ui.AgriculturalMyCircleListActivity;
import com.isunland.managesystem.ui.AgriculturalMyCollectListActivity;
import com.isunland.managesystem.ui.AgricultureGroomListActivity;
import com.isunland.managesystem.ui.AgricultureGroomListFragment;
import com.isunland.managesystem.ui.AgricultureServiceActivity;
import com.isunland.managesystem.ui.AgricultureServiceFragment;
import com.isunland.managesystem.ui.AppointmentOrderListActivity;
import com.isunland.managesystem.ui.AttendancePagerActivity;
import com.isunland.managesystem.ui.AttendanceSummaryListActivity;
import com.isunland.managesystem.ui.AttendanceSummaryQueryListActivity;
import com.isunland.managesystem.ui.BuyApplyListActivity;
import com.isunland.managesystem.ui.CarUsedApplyListActivity;
import com.isunland.managesystem.ui.CarUsedListActivity;
import com.isunland.managesystem.ui.CommonMessageListActivity;
import com.isunland.managesystem.ui.CompanyEventsListActivity;
import com.isunland.managesystem.ui.CompanyForumTypeActivity;
import com.isunland.managesystem.ui.CustomerAddressBookActivity;
import com.isunland.managesystem.ui.CustomerListActivity;
import com.isunland.managesystem.ui.CustomerNeedListActivity;
import com.isunland.managesystem.ui.CustomerProblemBackActivity;
import com.isunland.managesystem.ui.CustomerProblemListActivity;
import com.isunland.managesystem.ui.CustomerVisitHintListActivity;
import com.isunland.managesystem.ui.DelegateTaskActivity;
import com.isunland.managesystem.ui.DeliveryListActicity;
import com.isunland.managesystem.ui.DepartmentCollectActivity;
import com.isunland.managesystem.ui.EmployeeLoanActivity;
import com.isunland.managesystem.ui.FinanceFindListActivity;
import com.isunland.managesystem.ui.GenerateCodeActivity;
import com.isunland.managesystem.ui.KnowledgeAnnounceListActivity;
import com.isunland.managesystem.ui.KnowledgeBaseListActivity;
import com.isunland.managesystem.ui.LaTestAnnounceMentActivity;
import com.isunland.managesystem.ui.LeaseOrderListActivity;
import com.isunland.managesystem.ui.LocaleWorkQueryCountListActivity;
import com.isunland.managesystem.ui.MessagePagerActivity;
import com.isunland.managesystem.ui.MonthAttendanceListActivity;
import com.isunland.managesystem.ui.OnlineReceiveOrderListActivity;
import com.isunland.managesystem.ui.OrderSaleCollectActivity;
import com.isunland.managesystem.ui.PayMoneyLogPagerActivity;
import com.isunland.managesystem.ui.PersonalScoreListActivity;
import com.isunland.managesystem.ui.PhoneNumberActivity;
import com.isunland.managesystem.ui.PlanApproveActivity;
import com.isunland.managesystem.ui.PlanManageListActivity;
import com.isunland.managesystem.ui.ProductDevelopListActivity;
import com.isunland.managesystem.ui.ProductLedgerListActivity;
import com.isunland.managesystem.ui.ProductSalesListActivity;
import com.isunland.managesystem.ui.ProjectCollectListActivity;
import com.isunland.managesystem.ui.ProjectLedgerListActivity;
import com.isunland.managesystem.ui.ProjectListActivity;
import com.isunland.managesystem.ui.PublishAccnouceListActivity;
import com.isunland.managesystem.ui.ReceiptListActicity;
import com.isunland.managesystem.ui.RequestPagerActivity;
import com.isunland.managesystem.ui.RequisitionListActivity;
import com.isunland.managesystem.ui.RetailInListActivity;
import com.isunland.managesystem.ui.RetailOutListActivity;
import com.isunland.managesystem.ui.RetailOutMainDetailFragment;
import com.isunland.managesystem.ui.ScoreApprovalListActivity;
import com.isunland.managesystem.ui.ScoreRankListActivity;
import com.isunland.managesystem.ui.SealUseListActivity;
import com.isunland.managesystem.ui.SettingActivity;
import com.isunland.managesystem.ui.ShouldGatherPayListActivity;
import com.isunland.managesystem.ui.SignFieldActivity;
import com.isunland.managesystem.ui.SimpleWebViewActivity;
import com.isunland.managesystem.ui.StaffScoreFillListActivity;
import com.isunland.managesystem.ui.StockMaterialListActivity;
import com.isunland.managesystem.ui.TaskCollectActivity;
import com.isunland.managesystem.ui.TaskListActivity;
import com.isunland.managesystem.ui.TaskListFragment;
import com.isunland.managesystem.ui.VideoActivity;
import com.isunland.managesystem.ui.WorkAreaSearchListActivity;
import com.isunland.managesystem.ui.WorkProcessListActivity;
import com.isunland.managesystem.ui.WorkRequestListActivity;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/6/30 10:55
 */

public class ConfigUtil {
  @SuppressLint("StaticFieldLeak") private static ConfigUtil sConfigUtil;
  private static HashMap<Integer, FunctionObject> sMap;
  @SuppressWarnings({ "FieldCanBeLocal", "unused" }) private Context mContext;

  private ConfigUtil(Context context) {
    this.mContext = context;
    sMap = initMap(context);
  }

  public static FunctionObject get(Context context, int key) {
    if (context == null) return new FunctionObject();
    if (sMap == null) newInstance(context);
    if (key == 0 || sMap.get(key) == null) return null;
    return sMap.get(key);
  }

  public static ConfigUtil newInstance(Context context) {
    if (sConfigUtil == null) {
      sConfigUtil = new ConfigUtil(context);
    }
    return sConfigUtil;
  }

  public static void startByCode(BaseVolleyActivity context, int code) {
    if (code == 0 || context == null) return;
    FunctionObject config = ConfigUtil.newInstance(context).getMap().get(code);
    if (config == null) return;
    Intent intent = config.getIntent();
    if (intent == null) return;
    if (config.getCode() == 2016) {
      intent.putExtra(AgriculturalForumListFragment.EXTRA_JOBNO,
          CurrentUser.newInstance(context).getJobNumber());
    }
    //使用新的配置的方式启动Activiy.
    if (config.getParams() != null) {
      try {
        //noinspection unchecked
        BaseVolleyActivity.newInstance(context, config.getActivityClassName(), config.getParams(),
            0);
      } catch (Exception e) {
        e.printStackTrace();
        context.startActivity(intent);
      }
    } else {
      context.startActivity(intent);
    }
    config.excuteDynamic(context);
    config.setSharedPreference(context);
  }

  public HashMap<Integer, FunctionObject> getMap() {
    return sMap;
  }

  /** 这里的配置intent只能使用固定的,不能用动态的. */
  private HashMap<Integer, FunctionObject> initMap(Context context) {
    //CurrentUser user = CurrentUser.newInstance(context);
    @SuppressLint("UseSparseArrays") HashMap<Integer, FunctionObject> map = new HashMap<>();
    ArrayList<FunctionObject> list = new ArrayList<>();
    //Intent intent=new Intent();
    //list.add(new FunctionObject(1, "考勤打卡", new Intent(context,AttendancePagerActivity.class)));
    //list.add(new FunctionObject(2, "我的消息",new Intent(context, MessagePagerActivity.class)));
    //list.add(new FunctionObject(3, "最新公告", new Intent(context,LaTestAnnounceMentActivity.class)));
    //list.add(new FunctionObject(4, "待办任务", new Intent(context,TaskListActivity.class)));
    list.add(new FunctionObject(5, "设置", new Intent(context, SettingActivity.class)));

    list.add(new FunctionObject(11, "外勤签到", new Intent(context, SignFieldActivity.class)));// 外勤签到
    list.add(
        new FunctionObject(12, "考勤申请", new Intent(context, RequisitionListActivity.class)));// 考勤申请
    list.add(
        new FunctionObject(13, "考勤汇总", new Intent(context, AttendanceSummaryListActivity.class)));//
    list.add(new FunctionObject(14, "月考勤数据考勤汇总",
        new Intent(context, MonthAttendanceListActivity.class)));// 月考勤数据考勤汇总
    list.add(new FunctionObject(15, "考勤申请单汇总查询",
        new Intent(context, AttendanceSummaryQueryListActivity.class)));// 考勤申请单汇总查询
    list.add(new FunctionObject(21, "待办任务", new Intent(context, TaskListActivity.class)));//待办
    list.add(new FunctionObject(22, "已办任务",
        new Intent(context, TaskListActivity.class).putExtra(TaskListFragment.EXTRA_MENU_ID,
            TaskListFragment.MY_DONE_LIST)));//已办
    list.add(new FunctionObject(23, "我的请求与办结",
        new Intent(context, RequestPagerActivity.class)));//我的请求与办结
    //list.add(new FunctionObject(31, 5, "工作任务", new Intent(context, WorkProcessListActivity.class)));
    list.add(new FunctionObject(32, "委派任务", new Intent(context, DelegateTaskActivity.class)));
    list.add(new FunctionObject(33, "计划审批", new Intent(context, PlanApproveActivity.class)));
    list.add(new FunctionObject(34, "任务汇总", new Intent(context, TaskCollectActivity.class)));
    list.add(new FunctionObject(41, "产品台账", new Intent(context, ProductLedgerListActivity.class)));
    list.add(new FunctionObject(42, "客户名录", new Intent(context, CustomerListActivity.class),
        context.getString(R.string.module_deptColumns)));
    list.add(new FunctionObject(43, "产品实销数据列表", new Intent(context, ProductSalesListActivity.class),
        context.getString(R.string.module_subConColumns)));
    list.add(
        new FunctionObject(44, "产品开发费用列表", new Intent(context, ProductDevelopListActivity.class),
            context.getString(R.string.module_developExpenseEecord)));
    list.add(new FunctionObject(45, 10, "客户问题处理登记",
        new Intent(context, CustomerProblemListActivity.class)));//客户问题处理登记
    list.add(
        new FunctionObject(46, "客户通讯录", new Intent(context, CustomerAddressBookActivity.class)));
    list.add(new FunctionObject(47, 9, "客户拜访提醒",
        new Intent(context, CustomerVisitHintListActivity.class), new BaseParams()));

    list.add(new FunctionObject(51, "个人财务列表", new Intent(context, EmployeeLoanActivity.class),
        context.getString(R.string.module_appFinance)));
    list.add(
        new FunctionObject(52, "部门收入支出汇总列表", new Intent(context, DepartmentCollectActivity.class)));

    list.add(
        new FunctionObject(61, "企业通讯录", new Intent(context, PhoneNumberActivity.class)));//企业通信录
    list.add(
        new FunctionObject(62, 1, "我的消息", new Intent(context, MessagePagerActivity.class)));//我的消息
    list.add(new FunctionObject(63, "企业交流论坛",
        new Intent(context, CompanyForumTypeActivity.class)));//企业交流论坛
    list.add(new FunctionObject(64, "知识公文查阅",
        new Intent(context, KnowledgeAnnounceListActivity.class)));//只是公文查阅
    list.add(new FunctionObject(65, "发布企业公告",
        new Intent(context, PublishAccnouceListActivity.class)));//发布企业公告
    list.add(new FunctionObject(66, "日常办公协作",
        new Intent(context, WorkRequestListActivity.class)));//日常办公协作
    list.add(new FunctionObject(67, "车辆使用情况登记",
        new Intent(context, CarUsedListActivity.class)));//车辆使用情况登记
    list.add(new FunctionObject(68, "公司大事记",
        new Intent(context, CompanyEventsListActivity.class)));//公司大事记
    list.add(new FunctionObject(69, "工作日程管理",
        new Intent(context, PlanManageListActivity.class)));//工作日程管理
    list.add(new FunctionObject(610, "工器具领用出库", new Intent(context, RetailOutListActivity.class),
        new BaseParams().setCode("-DJLB-OUT-GQJLYCK")
            .setName("工器具领用出库")
            .setRemark("outBill_Tool")
            .setFrom(RetailOutMainDetailFragment.TOOL)));//工器具领用出库

    list.add(new FunctionObject(71, "应收应付查询",
        new Intent(context, ShouldGatherPayListActivity.class)));//应收应付查询
    list.add(new FunctionObject(72, "合同开票", new Intent(context, ReceiptListActicity.class)));//合同开票

    //list.add(
    //    new FunctionObject(81, "销售订单填报", new Intent(context, OderSaleListActivity.class)));//销售订单填报
    list.add(new FunctionObject(81, "销售订单填报", new Intent(context, RetailOutListActivity.class),
        new BaseParams().setCode("-DJLB-OUT-XSDDCK")
            .setName("销售订单填报")
            .setRemark("outBill_SaleOrder")
            .setFrom(RetailOutMainDetailFragment.ORDER)));//销售订单填报,remark是子表配置的resourceFlag

    list.add(
        new FunctionObject(82, "配送发货管理", new Intent(context, DeliveryListActicity.class)));//配送发货管理
    list.add(new FunctionObject(85, "出入库汇总查询",
        new Intent(context, OrderSaleCollectActivity.class)));//出入库汇总查询
    list.add(
        new FunctionObject(86, "库存物料查询", new Intent(context, StockMaterialListActivity.class)));

    list.add(new FunctionObject(87, "零售出库", new Intent(context, RetailOutListActivity.class),
        new BaseParams().setCode("-DJLB-OUT-LSCK")
            .setName("零售出库")
            .setRemark("outBill_Sale")
            .setFrom(RetailOutMainDetailFragment.SALE)));//零售出库,remark是子表配置的resourceFlag

    list.add(new FunctionObject(88, "物料生产出库", new Intent(context, RetailOutListActivity.class),
        new BaseParams().setCode("-DJLB-OUT-WLCK")
            .setName("物料生产出库")
            .setRemark("outBill_Material")
            .setFrom(RetailOutMainDetailFragment.MATERIAL)));//物料生产出库,remark是子表配置的resourceFlag

    list.add(
        new FunctionObject(89, "零购入库申请", new Intent(context, RetailInListActivity.class)));//零购入库申请

    list.add(
        new FunctionObject(91, "项目进度登记", new Intent(context, ProjectListActivity.class)));//项目进度登记
    list.add(new FunctionObject(92, "项目查询统计",
        new Intent(context, ProjectCollectListActivity.class)));//项目查询统计
    list.add(new FunctionObject(101, "奖惩积分填报",
        new Intent(context, StaffScoreFillListActivity.class)));//奖惩积分填报
    list.add(
        new FunctionObject(102, "奖惩积分查询", new Intent(context, PersonalScoreListActivity.class)));
    list.add(new FunctionObject(103, "会议签到", new Intent(context, GenerateCodeActivity.class),
        new GenerateCodeParams().setQrCodeType(GenerateCodeParams.TYPE_SCAN)));
    list.add(new FunctionObject(121, "奖惩积分排名",
        new Intent(context, ScoreRankListActivity.class)));//奖惩积分排名
    list.add(new FunctionObject(105, 6, "奖惩积分审批",
        new Intent(context, ScoreApprovalListActivity.class)));//奖惩积分审批
    list.add(
        new FunctionObject(110, "考勤打卡", new Intent(context, AttendancePagerActivity.class)));//考勤打卡
    list.add(new FunctionObject(111, 2, "待办事宜",
        new Intent(context, TaskListActivity.class).putExtra(TaskListFragment.EXTRA_MENU_ID,
            TaskListFragment.MY_TODO_LIST)));//待办事宜
    list.add(new FunctionObject(112, 5, "工作任务",
        new Intent(context, WorkProcessListActivity.class)));//工作任务
    list.add(new FunctionObject(113, 4, "最新公告",
        new Intent(context, LaTestAnnounceMentActivity.class)));//最新公告
    list.add(new FunctionObject(114, "项目台账登记",
        new Intent(context, ProjectLedgerListActivity.class)));//项目台账登记
    list.add(new FunctionObject(115, "客户需求与往来",
        new Intent(context, CustomerNeedListActivity.class)));//客户需求与往来
    list.add(new FunctionObject(118, "车辆使用申请",
        new Intent(context, CarUsedApplyListActivity.class)));//车辆使用申请
    list.add(
        new FunctionObject(120, "采购申请", new Intent(context, BuyApplyListActivity.class)));//采购申请
    list.add(new FunctionObject(119, "企业证章使用申请", new Intent(context, SealUseListActivity.class)));

    list.add(new FunctionObject(2001, "呼叫服务",
        new Intent(context, AppointmentOrderListActivity.class)));//呼叫服务
    list.add(new FunctionObject(2002, "农机服务",
        new Intent(context, AgricultureServiceActivity.class).putExtra(
            AgricultureServiceFragment.EXTRA_TITLE, context.getString(R.string.trechForum))));//农机服务
    list.add(new FunctionObject(2003, "农技服务",
        new Intent(context, AgricultureServiceActivity.class).putExtra(
            AgricultureServiceFragment.EXTRA_TITLE,
            context.getString(R.string.AgricultureService))));//农技服务
    list.add(new FunctionObject(2004, "农业知识库",
        new Intent(context, KnowledgeBaseListActivity.class)));//农业知识库
    list.add(new FunctionObject(2005, "公共服务消息",
        new Intent(context, CommonMessageListActivity.class)));//公共服务消息
    list.add(new FunctionObject(2006, "观光农业认养",
        new Intent(context, AgricultureGroomListActivity.class).putExtra(
            AgricultureGroomListFragment.EXTRA_TYPE,
            AgricultureGroomListFragment.AGRICULTURAL_VISIT)));//观光农业认养
    list.add(new FunctionObject(2007, "农资交易中心",
        new Intent(context, AgricultureGroomListActivity.class).putExtra(
            AgricultureGroomListFragment.EXTRA_TYPE,
            AgricultureGroomListFragment.AGRICULTURAL_PRODUCTION)));//农资交易中心
    list.add(new FunctionObject(2008, "发现",
        new Intent(context, FinanceFindListActivity.class)));//金融保险,更名为发现
    list.add(new FunctionObject(2009, "设备在线租赁",
        new Intent(context, LeaseOrderListActivity.class)));//设备在线租赁
    list.add(new FunctionObject(2010, "用户问题反馈",
        new Intent(context, CustomerProblemBackActivity.class)));//用户问题反馈
    list.add(new FunctionObject(2011, "作业任务",
        new Intent(context, LocaleWorkQueryCountListActivity.class)));//作业完任务登记
    list.add(new FunctionObject(2012, "接单服务",
        new Intent(context, OnlineReceiveOrderListActivity.class)));//接单服务
    list.add(new FunctionObject(2013, "地块库",
        new Intent(context, WorkAreaSearchListActivity.class)));//地块库
    list.add(new FunctionObject(2014, "支付中心",
        new Intent(context, PayMoneyLogPagerActivity.class)));//支付中心
    //map中是固定死的配置,不会刷新位置.经纬度必须通过其他方式传递.

    list.add(new FunctionObject(2015, "高清地图", new Intent(context, SimpleWebViewActivity.class),
        new SimpleWebViewParams().setUrl(ApiConst.URL_HDMAP)
            .setRefreshButton(true)
            .setLoadLocationUrl(true)));
    list.add(new FunctionObject(2016, "收藏圈",
        new Intent(context, AgriculturalMyCollectListActivity.class)));
    list.add(new FunctionObject(2017, "朋友圈",
        new Intent(context, AgriculturalMyCircleListActivity.class)));
    list.add(new FunctionObject(2018, "视频播放", new Intent(context, VideoActivity.class)));
    for (FunctionObject functionObject : list) {
      map.put(functionObject.getCode(), functionObject);
    }
    return map;
  }
}
